﻿local QI = DailyIntake.QuestItems;
local Localize = DailyIntake.Localize;

--------------------------------------------------------------------------------
-- Frenzyheart quest items
--------------------------------------------------------------------------------

-- Add item: Chicken Net; http://www.wowhead.com/?item=38689
local function ChickenNet()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- an area around and including Frenzyheart Hill, 
        -- those chickens often run outside the hill, so had to cover that area
        and QI.PlayerIsInArea(0.655, 0.521, 0.781,  0.626)
        
        -- must not have completed quest objective yet
        and GetItemCount(38483) < 12; -- Captured Chicken
end;
QI.RegisterQuestItem(38689, QI.Priority.Normal, ChickenNet);

-- Add item: Oracle Blood; http://www.wowhead.com/?item=39265
local function OracleBlood()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must be next to an altar
        and QI.PlayerIsCloseTo(0.23255906999111, 0.83068341016769, 0.00272)
        
        -- must not have completed quest objective yet
        and not QI.QuestObjectiveIsDone(12703, 1);
end
QI.RegisterQuestItem(39265, QI.Priority.Normal, OracleBlood);

-- Add item: Rejek's Vial; http://www.wowhead.com/?item=39574
local function RejeksVial()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must be at Suntouched Pillar at the top
        and QI.PlayerIsCloseTo(0.33346530795097, 0.52391290664673, 0.00943);
end;
QI.RegisterQuestItem(39574, QI.Priority.Low, RejeksVial);

-- Add item: Suntouched Water; http://www.wowhead.com/?item=39576
local function SuntouchedWater()
    return not UnitOnTaxi("player")
        
        -- must have Matriarch's Heartblood in inventory; http://www.wowhead.com/?item=39573
        and GetItemCount(39573) > 0;
end;
QI.RegisterQuestItem(39576, QI.Priority.Lower, SuntouchedWater);

-- Add item: Rejek's Blade; http://www.wowhead.com/?item=39577
local function RejeksBlade()
    return not UnitOnTaxi("player")
        
        -- must not be tapped by other players
        and not QI.UnitIsTappedByOtherPlayer("target")
        and UnitIsDead("target") == 1
        
        -- must target propper target for corresponding objective
        and ((QI.UnitIsEntity("target", 28086, QI.Entity.Mob) and not QI.QuestObjectiveIsDone(12734, 1)) or -- Sapphire Hive Wasp (http://www.wowhead.com/?npc=28086)
             (QI.UnitIsEntity("target", 28096, QI.Entity.Mob) and not QI.QuestObjectiveIsDone(12734, 2)) or -- Hardknuckle Charger (http://www.wowhead.com/?npc=28096)
             ((QI.UnitIsEntity("target", 28110, QI.Entity.Mob) or QI.UnitIsEntity("target", 28109, QI.Entity.Mob)) and not QI.QuestObjectiveIsDone(12734, 3)) -- Mistwhisper Oracle (http://www.wowhead.com/?npc=28110) or Mistwhisper Warrior (http://www.wowhead.com/?npc=28109)
            );
end;
QI.RegisterQuestItem(39577, QI.Priority.Highest, RejeksBlade);

-- Add item: Wolvar Berries; http://www.wowhead.com/?item=39739
local function WolvarBerries()
    return not UnitOnTaxi("player")
        
        -- must have Thunderbrew's Hard Ale in inventory; http://www.wowhead.com/?item=39738
        and GetItemCount(39738) > 0;
end;
QI.RegisterQuestItem(39739, QI.Priority.Lower, WolvarBerries);

-- Add item: Secret Strength of the Frenzyheart; http://www.wowhead.com/?item=39737
local function SecretStrengthOfTheFrenzyheart()
    return not UnitOnTaxi("player")
        
        -- must be in right location
        and GetZoneText() == Localize("Sholazar Basin")
        and GetSubZoneText() == Localize("Sparktouched Haven")
        
        -- must not have completed the quest yet
        and not QI.QuestIsDone(12760); -- Secret Strength of the Frenzyheart (http://www.wowhead.com/?quest=12760)
end;
QI.RegisterQuestItem(39737, QI.Priority.Lowest, SecretStrengthOfTheFrenzyheart);

-- Add item: Venture Co. Explosives; http://www.wowhead.com/?item=39651
local function VentureCoExplosives()
    return not UnitOnTaxi("player")
        
        -- must be in right location
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must target dead Stormwatcher (http://www.wowhead.com/?npc=28877)
        and not QI.UnitIsTappedByOtherPlayer("target")
        and QI.UnitIsEntity("target", 28877, QI.Entity.Mob)
        and UnitIsDead("target")
        
        -- must not have completed the quest yet
        and not QI.QuestIsDone(12758); -- A Hero's Headgear (http://www.wowhead.com/?quest=12758)
end;
QI.RegisterQuestItem(39651, QI.Priority.Highest, VentureCoExplosives);


--------------------------------------------------------------------------------
-- Oracle quest items
--------------------------------------------------------------------------------
-- Add multiple items to summon oracle companion: 
-- * Lafoo's Bug Bag; http://www.wowhead.com/?item=38622
-- * Jaloot's Favorite Crystal; http://www.wowhead.com/?item=38623
-- * Moodle's Stress Ball; http://www.wowhead.com/?item=38624
-- these items have the same function because the serve the same purpose.
local function OracleCompanion()
    local objectiveComplete, questNotTaken = QI.QuestObjectiveIsDone(12704, 1);
    
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must have the quest
        and not questNotTaken
        
        -- must not have the quest completed
        and not objectiveComplete
        
        -- must be in area around Rainspeaker Canopy
        and QI.PlayerIsInArea(0.47, 0.48, 0.63, 0.6);
end;
QI.RegisterQuestItem(38622, QI.Priority.Lower, OracleCompanion);
QI.RegisterQuestItem(38623, QI.Priority.Lower, OracleCompanion);
QI.RegisterQuestItem(38624, QI.Priority.Lower, OracleCompanion);

-- Add item: Chime of Cleansing; http://www.wowhead.com/?item=39572
local function ChimeOfCleansing()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must have one of the objectives incomplete
        -- and must be in an area corresponding to that objective
        and (
            -- Spirit of Atha killed or
            (not QI.QuestObjectiveIsDone(12735, 1) and GetSubZoneText() == Localize("Bittertide Lake")) or
            
            -- Spirit of Ha-Khalan killed or
            (not QI.QuestObjectiveIsDone(12735, 2) and GetSubZoneText() == Localize("River's Heart")) or
            
            -- Spirit of Koosu killed or
            (not QI.QuestObjectiveIsDone(12735, 3) and GetSubZoneText() == Localize("Wintergrasp River"))
            );
end;
QI.RegisterQuestItem(39572, QI.Priority.Lower, ChimeOfCleansing);

-- Add several items for quest: Mastery of the Crystals; http://www.wowhead.com/?quest=12761
-- * Crystal of the Frozen Grip; http://www.wowhead.com/?item=39689
-- * Crystal of the Violent Storm; http://www.wowhead.com/?item=39694
-- * Crystal of Unstable Energy; http://www.wowhead.com/?item=39693
local function GetMasteryOfTheCrystalsMacro()
    local itemList = {};
    if GetItemCount(39694) > 0 then table.insert(itemList, "item:39694"); end;
    if GetItemCount(39689) > 0 then table.insert(itemList, "item:39689"); end;
    if GetItemCount(39693) > 0 then table.insert(itemList, "item:39693"); end;
    
    return "#showtooltip\n/castsequence reset=15 " .. strjoin(",", unpack(itemList));
end;

local function MasteryOfTheCrystals()
    local conditionsPassed = 
        not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must not have completed the quest
        and not QI.QuestObjectiveIsDone(12761, 1)
        
        -- must be in appropriare area
        and (GetSubZoneText() == Localize("Sparktouched Haven") 
          or GetSubZoneText() == Localize("Path of the Lifewarden")
          or GetSubZoneText() == Localize("Kartak's Hold")
          );
        
    if conditionsPassed then
        return true, GetMasteryOfTheCrystalsMacro();
    end;
end;
QI.RegisterQuestItem(39694, QI.Priority.Low, MasteryOfTheCrystals);
QI.RegisterQuestItem(39689, QI.Priority.Low, MasteryOfTheCrystals);
QI.RegisterQuestItem(39693, QI.Priority.Low, MasteryOfTheCrystals);

-- Add item: Didgeridoo of Contemplation; http://www.wowhead.com/?item=39598
local function DidgeridooOfContemplation()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must have one of the objectives incomplete
        -- and must be in an area corresponding to that objective
        and (
            (not QI.QuestObjectiveIsDone(12736, 1) and GetSubZoneText() == Localize("Glimmering Pillar")) or
            (not QI.QuestObjectiveIsDone(12736, 2) and GetSubZoneText() == Localize("Mosslight Pillar")) or
            (not QI.QuestObjectiveIsDone(12736, 3) and GetSubZoneText() == Localize("Skyreach Pillar")) or
            (not QI.QuestObjectiveIsDone(12736, 4) and GetSubZoneText() == Localize("Suntouched Pillar"))
            );
end;
QI.RegisterQuestItem(39598, QI.Priority.Low, DidgeridooOfContemplation);

-- Add item: Dormant Polished Crystal; http://www.wowhead.com/?item=39747
local function DormantPolishedCrystal()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must be at Sparktouched Haven
        and QI.PlayerIsCloseTo(0.65663826465607,  0.59538078308105, 0.00943);
end;
QI.RegisterQuestItem(39747, QI.Priority.Low, DormantPolishedCrystal);

-- Add item: Energized Polished Crystal; http://www.wowhead.com/?item=39748
local function EnergizedPolishedCrystal()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must not have completed the quest
        and not (QI.QuestObjectiveIsDone(12762, 1) and QI.QuestObjectiveIsDone(12762, 2))
        
        -- must be in appropriare area
        and (GetSubZoneText() == Localize("Sparktouched Haven") 
          or GetSubZoneText() == Localize("Path of the Lifewarden")
          or GetSubZoneText() == Localize("Kartak's Hold")
          );
end;
QI.RegisterQuestItem(39748, QI.Priority.Low, EnergizedPolishedCrystal);

-- Add item: Drums of the Tempest; http://www.wowhead.com/?item=39571
local function DrumsOfTheTempest()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must not have completed the quest
        and not (QI.QuestObjectiveIsDone(12726, 1) and QI.QuestObjectiveIsDone(12726, 2))
        
        -- must be in appropriare area
        and GetSubZoneText() == Localize("Stormwright's Shelf");
end;
QI.RegisterQuestItem(39571, QI.Priority.Normal, DrumsOfTheTempest);

-- Add item: Horn of Fecundity; http://www.wowhead.com/?item=39599
local function HornOfFecundity()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must not have completed the quest
        and not QI.QuestIsDone(12737)
        
        -- must be in appropriare area
        and GetSubZoneText() == Localize("Stormwright's Shelf");
end;
QI.RegisterQuestItem(39599, QI.Priority.Normal, HornOfFecundity);

-- Add item: Tainted Crystal; http://www.wowhead.com/?item=39266
local function TaintedCrystal()
    return not UnitOnTaxi("player")
        and GetZoneText() == Localize("Sholazar Basin")
        
        -- must not have completed the quest
        and not QI.QuestIsDone(12705)
        
        -- must be in appropriare area
        and QI.PlayerIsCloseTo(0.33854520320892, 0.74980652332306, 0.00447);
end;
QI.RegisterQuestItem(39266, QI.Priority.Normal, TaintedCrystal);


-- =============================================================
-- Added by LaoTseu
-- =============================================================

-- The Ghostfish (http://www.wowhead.com/?item=45902 http://www.wowhead.com/?quest=13830)
local function Ghostfish()
	return not UnitOnTaxi("player");
end;
QI.RegisterQuestItem(45902, QI.Priority.Highest, Ghostfish);

